﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jemer.Domain;
using Jemer.Data;
using Jemer.Data.Infrastructure;
using Jemer.Domain.Entities;
using Jemer.Data.Repositories;

namespace Jemer.Service
{
    
    public interface IUserArchiveService
    {
        IQueryable<UserArchive> GetUserArchives();
        UserArchive GetUserArchive(int id);
        void CreateUserArchive(UserArchive userArchive);
        void DeleteUserArchive(int id);
        void SaveUserArchive();
    }
    
    public class UserArchiveService : IUserArchiveService
    {
        private readonly IUserArchiveRepository userArchiveRepository;
        private readonly IUnitOfWork unitOfWork;
        public UserArchiveService(IUserArchiveRepository userArchiveRepository, IUnitOfWork unitOfWork)
        {
            this.userArchiveRepository = userArchiveRepository;
            this.unitOfWork = unitOfWork;
        }  
        #region IUserArchiveService Members

        public IQueryable<UserArchive> GetUserArchives()
        {
            var userArchives = userArchiveRepository.GetAll();
            return userArchives;
        }

        public UserArchive GetUserArchive(int id)
        {
            var userArchive = userArchiveRepository.GetById(id);
            return userArchive;
        }

        public void CreateUserArchive(UserArchive userArchive)
        {
            userArchiveRepository.Add(userArchive);
            SaveUserArchive();
        }

        public void DeleteUserArchive(int id)
        {
            var userArchive = userArchiveRepository.GetById(id);
            userArchiveRepository.Delete(userArchive);
            SaveUserArchive();
        }

        public void SaveUserArchive()
        {
            unitOfWork.Commit();
        }

        #endregion
    }
    
    
}